package com.example.hospitalmanagement.fragment

import android.content.Intent
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.databinding.DataBindingUtil
import androidx.fragment.app.Fragment
import androidx.recyclerview.widget.GridLayoutManager
import com.example.hospitalmanagement.R
import com.example.hospitalmanagement.activity.*
import com.example.hospitalmanagement.adapter.HomeFragmentAdapter
import com.example.hospitalmanagement.adapter.ServiceFragmentAdapter
import com.example.hospitalmanagement.bean.DiagnosisAndTreatmentItem
import com.example.hospitalmanagement.databinding.FragmentHomeBinding
import kotlinx.android.synthetic.main.fragment_home.*

/**
 * 医院综合页面Fragment
 */
class HomeFragment : Fragment() {

    private lateinit var fragmentHome: FragmentHomeBinding

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View {
        fragmentHome = DataBindingUtil.inflate(
            inflater, R.layout.fragment_home, container, false
        )
        return fragmentHome.root
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        initView()
    }

    private fun initView() {
        home_large_icon_item.layoutManager = GridLayoutManager(requireActivity(), 3)
        val dataList: MutableList<DiagnosisAndTreatmentItem> = mutableListOf(
            DiagnosisAndTreatmentItem(
                R.mipmap.hospital_introduction, "医院介绍"
            ),
            DiagnosisAndTreatmentItem(
                R.mipmap.department_introduction, "科室介绍"
            ),
            DiagnosisAndTreatmentItem(
                R.mipmap.expert_introduction, "专家介绍"
            )
        )
        val adapter = HomeFragmentAdapter(requireActivity())
        adapter.dataList = dataList
        home_large_icon_item.adapter = adapter

        home_item.layoutManager = GridLayoutManager(requireActivity(), 4)
        val homeItems: MutableList<DiagnosisAndTreatmentItem> = mutableListOf(
            DiagnosisAndTreatmentItem(
                R.mipmap.health_education,
                "健康宣教"
            ), DiagnosisAndTreatmentItem(
                R.mipmap.medical_insurance_policy,
                "医保政策"
            ), DiagnosisAndTreatmentItem(
                R.mipmap.price_announcement,
                "价格公示"
            ), DiagnosisAndTreatmentItem(
                R.mipmap.satisfaction_surveys,
                "满意度调查"
            )
        )
        val homeItemsAdapter = ServiceFragmentAdapter(requireActivity())
        homeItemsAdapter.dataList = homeItems
        home_item.adapter = homeItemsAdapter
        adapter.setListener {
            when(it){
                0->{
                    startActivity(Intent(requireActivity(),HospitalIntroductionActivity().javaClass))
                }
                1->{
                    startActivity(Intent(requireActivity(),DepartmentActivity().javaClass))
                }
                2->{
                    startActivity(Intent(requireActivity(),ExpertIntroductionActivity().javaClass))
                }
            }
        }
        homeItemsAdapter.setListener {
            when(it){
                0->{
                    startActivity(Intent(requireActivity(),HealthEducationActivity().javaClass))
                }
                1->{
                    startActivity(Intent(requireActivity(),MedicalInsurancePolicyActivity().javaClass))
                }
                2->{
                    startActivity(Intent(requireActivity(),PriceAnnouncementActivity().javaClass))
                }
                3->{}
            }
        }
    }
}
